package com.bdilab.iot.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bdilab.iot.model.Permission;
import com.bdilab.iot.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WangNing
 * @version 1.0
 * @date 2020/7/31 16:49
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from `user` where `username` = #{username}")
    User selectByUserName(@Param("username") String username);

    @Select("select  p.id as id, p.name as name, p.create_time as create_time from    user as u \n" +
            "left join user_role_relation urr on u.id = urr.user_id\n" +
            "left join role r on urr.role_id = r.id\n" +
            "left join role_permission_relation rpr on r.id = rpr.role_id\n" +
            "left join permission p on rpr.permission_id = p.id\n" +
            "where u.id = #{id}")
    List<Permission> getPermissionById(@Param("id") Long id);

    @Select("select count(1) from `user` where username = #{username} ")
    Integer countByUsername(String username);

    int updateUser(User user);

}
